package com.relax.netty.tcp.encode;

import com.relax.netty.tcp.decode.Person;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

public class MyEncode extends MessageToByteEncoder<Person> {
    @Override
    protected void encode(ChannelHandlerContext ctx, Person person, ByteBuf out) throws Exception {
        long length = person.getLength();
        out.writeShort((int) length);
        out.writeBytes(person.getName().getBytes());
    }
}
